package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.menu.MenuTreeVo;
import cn.da.shuai.cool.system.model.entity.menu.SearchMenuVo;
import cn.da.shuai.cool.system.model.entity.menu.UpdateMenuVo;
import cn.da.shuai.cool.system.service.service.ICoolMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "菜单管理")
@RestController
@RequestMapping("/menu")
public class CoolMenuController {

    @Resource
    private ICoolMenuService coolMenuService;

    @Operation(summary = "获取菜单树")
    @PostMapping("/tree")
    public R<List<MenuTreeVo>> getMenuTree(@RequestBody(required = false) SearchMenuVo vo) {
        return R.ok(coolMenuService.getMenuTree(vo));
    }

    @Operation(summary = "新增菜单")
    @PostMapping("/add")
    public R<Boolean> addMenu(@RequestBody UpdateMenuVo vo) {
        coolMenuService.createMenu(vo);
        return R.ok(true);
    }

    @Operation(summary = "更新菜单")
    @PutMapping("/update")
    public R<Boolean> updateMenu(@RequestBody UpdateMenuVo vo) {
        coolMenuService.updateMenu(vo);
        return R.ok(true);
    }

    @Operation(summary = "删除菜单")
    @DeleteMapping("/delete/{id}")
    public R<Boolean> deleteMenu(@PathVariable Long id) {
        coolMenuService.deleteMenu(id);
        return R.ok(true);
    }
}